home *** CD-ROM | disk | FTP | other *** search
- /*
- cop.h -- C Object Programming v3.02:
- encapsulation, inheritance,
- and polymorphism.
-
- (C) Copyright 1992 John W. Small
- All rights reserved
-
- PSW / Power SoftWare
- P.O. Box 10072
- McLean, Virginia 22102 8072 USA
- Voice: (703) 759-3838
- */
-
- /* LINTLIBRARY */
-
- #ifndef COP_H
- #define COP_H
-
- #ifndef MALLOC
- #include <stdlib.h>
- #define MALLOC(size) malloc(size)
- #define FREE(ptr) free(ptr)
- #endif
-
- #define struct_vFt_forward(structType) \
- typedef struct structType ## _vFt_ \
- structType ## _vFt, * structType ## _vFT
-
- #define struct_(structType) \
- typedef struct structType ## _ structType; \
- struct structType ## _
- #define vFT_decl(structType) \
- structType ## _vFT vFT
- #define polymorphic() void * descendanT
- #define poly_assign(thiS,descendanT_0) \
- thiS->descendanT = descendanT_0
- #define derivedThiS(thiS,derivedStructType) \
- ((derivedStructType *) (thiS->descendanT))
- #define inherit(baseStructType) \
- baseStructType baseStructType ## Base
- #define baseThiS(thiS,baseStructType) \
- (&((thiS)->baseStructType ## Base))
- #define polyBaseThiS_0_decl(structFncPrefix, \
- polyBaseStructType,structType) extern \
- polyBaseStructType * structFncPrefix ##\
- _ ## polyBaseStructType ## ThiS_0 \
- (structType * thiS_0)
- #define polyBaseThiS_0_def(structFncPrefix, \
- polyBaseStructType, structType) \
- polyBaseStructType * structFncPrefix ##\
- _ ## polyBaseStructType ## ThiS_0 \
- (structType * thiS_0) { \
- return (thiS_0? structFncPrefix ##\
- _ ## polyBaseStructType ## ThiS(thiS_0) \
- : (polyBaseStructType *)0); }
-
- #define vbInherit(vbaseStructType) \
- vbaseStructType * vbaseStructType ## BasE
- #define vbThiS(thiS,vbaseStructType) \
- (thiS)->vbaseStructType ## BasE
- #define vbDerivedThiS(thiS,derivedStructType) \
- derivedThis(thiS,derivedStructType)
- #define struct_vbc(structType) \
- typedef struct vbh ## structType ##\
- _ vbh ## structType; \
- struct vbh ## structType ## _
- #define vbh_decl(structType) \
- structType host
- #define vb_decl(vbaseStructType) \
- vbaseStructType vb ## vbaseStructType
- #define vbhThiS(vbcThiS)
-
- #define static_def(structType) \
- structType ## _static structType ## Static
- #define struct_static(structType) \
- typedef struct structType ## _static_ \
- structType ## _static; \
- extern structType ## _static \
- structType ## Static; \
- struct structType ## _static_
- #define static_ref(structType,field) \
- structType ## Static. ## field
-
- #define struct_vFt(structType) \
- struct structType ## _vFt_
- #define vFt_def(overridingStructType, \
- spawningStructType) \
- spawningStructType ## _vFt \
- overridingStructType ## _ ##\
- spawningStructType ## _vFt
- #define vFt_decl(overridingStructType, \
- spawningStructType) extern \
- vFt_def(overridingStructType, \
- spawningStructType)
- #define vF_decl(returnValue,fncName, \
- formalParams) \
- returnValue (* fncName ) formalParams
- /* formalParams: (structType * thiS,...) */
- #define vF_value(overridingStructFncPrefix, \
- spawningStructFncPrefix, fncName) \
- overridingStructFncPrefix ## _ ##\
- spawningStructFncPrefix ## _ ## fncName
-
- #define vf_def(returnValue, \
- overridingStructFncPrefix, \
- spawningStructFncPrefix, fncName, \
- formalParams) \
- returnValue overridingStructFncPrefix ## _ ##\
- spawningStructFncPrefix ## _ ## fncName \
- formalParams
- /* formalParams: (structType * thiS, ...) */
- #define vf_decl(returnValue, \
- overridingStructFncPrefix, \
- spawningStructFncPrefix, fncName, \
- formalParams) \
- extern vf_def(returnValue, \
- overridingStructFncPrefix, \
- spawningStructFncPrefix,fncName, \
- formalParams)
- /* formalParams: (structType * thiS, ...) */
- #define vf_runTimeBind(spawningStructThiS, fncName, \
- actualParams) \
- (*((spawningStructThiS)->vFT->fncName)) \
- actualParams
- /* actualParams: (spawningStructThiS, ...) */
- #define vf_compileTimeBind( \
- overridingStructFncPrefix, \
- spawningStructFncPrefix, fncName, \
- actualParams) \
- overridingStructFncPrefix ## _ ##\
- spawningStructFncPrefix ## _ ## fncName \
- actualParams
- /* actualParams: (spawningStructThiS, ...) */
-
- #define vFT0(spawningStructType) \
- ((spawningStructType ## _vFT)0)
- #define vFT_0_name(spawningStructType) \
- spawningStructType ## _vFT_0
- #define vFT_0_decl(spawningStructType) \
- spawningStructType ## _vFT \
- spawningStructType ## _vFT_0
- #define vFT_value(overridingStructType, \
- spawningStructType) \
- (& overridingStructType ## _ ##\
- spawningStructType ## _vFt)
- #define vFT_assign(overridingStructType, \
- spawningStructType, spawningStructThiS, \
- spawningStructType_vFT_0) \
- spawningStructThiS->vFT = \
- (spawningStructType_vFT_0? \
- spawningStructType_vFT_0 : \
- vFT_value(overridingStructType, \
- spawningStructType))
-
- #define vbThiS_name(vbaseStructType) \
- vbaseStructType ## ThiS
- #define vbThiS_decl(vbaseStructType) \
- vbaseStructType * vbaseStructType ## ThiS
- #define vbDescendanT_0_decl(vbaseStructType) \
- void * vbaseStructType ## DescendanT_0
- #define vbDescendanT_value(vbaseStructType,thiS) \
- (vbaseStructType ## DescendanT_0 ? \
- vbaseStructType ## DescendanT_0 : thiS)
-
- #define struct_initVFTs_def(structFncPrefix, \
- formalParams) void PT_ ##\
- structFncPrefix ## _initVFTs formalParams
- /* formalParams:
- (structType * thiS
- // if polymorphic
- , void * descendanT_0
- // if vf's are introduced at structType
- , vFT_0_decl(structType)
- // The following depend on the hierarchy
- , vFT_0_decl(baseStructType)
- , vbThiS_decl(vbaseStructType)
- , vbDescendanT_0_decl(vbaseStructType)
- , vFT_0_decl(vbaseStructType)
- , vFT_0_decl(subbaseStructType)
- , ...
- )
- */
- #define struct_initVFTs_decl(structFncPrefix, \
- formalParams) extern struct_initVFTs_def \
- (structFncPrefix,formalParams)
- #define struct_initVFTs(structFncPrefix, actualParams)\
- PT_ ## structFncPrefix ## _initVFTs \
- actualParams
- /* actualParams:
- (thiS
- , descendanT_0
- , vFT0(structType) or
- vFT_value(derivedStructType,structType)
- , vFT0(baseStructType) or
- vFT_value(structType,baseStructType)
- , vbThiS_name(vbaseStructType)
- , vbDescendanT_value(vbaseStructType,thiS)
- , vFT0(vbaseStructType) or
- vFT_value(structType,vbaseStructType)
- , ...
- )
- */
-
- #define struct_init_def(structType, structFncPrefix, \
- structFncOvrLdSuffix, formalParams) \
- structType * PT_ ## structFncPrefix ##\
- _init ## structFncOvrLdSuffix formalParams
- /* formalParams:
- (structType * thiS_0
- , unsigned nobj
- // location of virtual base:
- , vbThiS_decl(vbaseStructType)
- , ... initializers
- )
- */
- #define struct_init_decl(structType, structFncPrefix, \
- structFncOvrLdSuffix, formalParams) \
- extern struct_init_def(structType, \
- structFncPrefix,structFncOvrLdSuffix, \
- formalParams)
- #define struct_init(structFncPrefix, \
- structFncOvrLdSuffix,actualParams) \
- PT_ ## structFncPrefix ## _init ##\
- structFncOvrLdSuffix actualParams
- /* actualParams:
- (thiS_0, nobj
- , vbThiS_name(vbaseStructType)
- , ... initializers
- )
- */
-
- #define struct_destruct_def(structType, \
- structFncPrefix) void PT_ ##\
- structFncPrefix ## _destruct \
- (structType * thiS_0, unsigned nobj, \
- int malloced)
- #define struct_destruct_decl(structType, \
- structFncPrefix) extern struct_destruct_def \
- (structType, structFncPrefix)
- #define struct_destruct(structFncPrefix, \
- thiS_0, nobj, malloced) \
- PT_ ## structFncPrefix ##\
- _destruct (thiS_0,nobj,malloced)
-
-
- #endif
-